<?php

class Costumer_lists extends CI_Controller {

    function __construct() {
        parent::__construct();
        if ($this->session->userdata('logged_in')) {
            $session_data = $this->session->userdata('logged_in');
            $data['username'] = $session_data['username'];
        } else {
            redirect('user_login/user', 'refresh');
        }
        $this->load->model('costumer_list');
        $this->load->model('user');
        $this->load->model('user_role');
        $this->load->library('user_id');
        $this->load->helper('user_helper');
        $this->load->helper('costumer_list_helper');
        if ($this->user_id->cek() == 0) {
            redirect('user_login/user', 'refresh');
        }
    }

    function index() {
        $data['id'] = $this->user_id->id();

        $data['i'] = 1;
        $config = array();
        $config["base_url"] = base_url() . "costumer_lists/index";
        $config["total_rows"] = $this->costumer_list->record_count();
        $config["per_page"] = 10;
        $config["uri_segment"] = 3;

        $this->pagination->initialize($config);

        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $data['access'] = $this->user_role->access($this->user_id->cek());
        $data["results"] = $this->costumer_list->fetch_costumer($config["per_page"], $page);
        $data["links"] = $this->pagination->create_links();

        $data['content'] = 'costumer_lists/index';
        $this->load->view('template/user', $data);
    }

    function show() {
        $data['id'] = $this->user_id->id();

        $id = $this->uri->segment(3);
        $data['access'] = $this->user_role->access($this->user_id->cek());
        $data['rows'] = $this->costumer_list->show($id);
        $data['content'] = 'costumer_lists/show';
        $this->load->view('template/user', $data);
    }

    function confirm() {
//        $access = $this->user_role->access($this->user_id->cek());
//        $this->user_role->chek($access, 'edit');
        $date = mktime(0, 0, 0, date("m"), date("d") + 30, date("y"));
        $expire = date("Y/m/d", $date);
        $id = $this->uri->segment(3);
        $this->costumer_list->confirm($id, $expire);
    }

//    function delete() {
//        $access = $this->user_role->access($this->user_id->cek());
//        $this->user_role->chek($access, 'delete');
//
//        $id = $this->uri->segment(3);
//        $this->costumer_list->delete($id);
//    }
    function delete() {
        $access = $this->user_role->access($this->user_id->cek());
        $this->user_role->chek($access, 'list_delete');

        $id = $this->uri->segment(3);
        $this->costumer_list->delete($id);
    }

}

?>
